set more off

use "dataset_nashville panel", clear

keep if !mi(votebarry1) & !mi(votebarry2)
  
keep id votebarry1 votebarry2 knowbarry* ideoself1 learnedbarrymorelib ideoself2

gen priorideoself = ideoself1

duplicates drop id, force

reshape i id
reshape j wave 1 2
reshape xij knowbarrymorelib votebarry  ideoself
reshape xi priorideoself learnedbarrymorelib 
reshape long

xtset id wave

gen post = wave - 1
gen lvotebarryXlearn = l.votebarry*learn
gen priorideoselfXlearn = priorideoself*learn
gen priorideoselfXpost = priorideoself*post
gen ideoselfXpost = ideoself*post

gen conservative = 1 if priorideoself > 4
replace conservative = 0 if priorideoself < 4

su votebarry conservative learn post if !mi(learned) & !mi(votebarry) & post == 0
su votebarry conservative learn post if !mi(learned) & !mi(votebarry) & post == 1

collapse votebarry (count) n = votebarry, by(conservative learn post)

keep if !mi(votebarry) & !mi(learned) & !mi(post) & !mi(conservative)

egen totaln = sum(n), by(post)

#delimit;

gr tw 
	(con votebarry post if conservative == 1 & learn == 1, col(black) msym(O) lpat(solid))
	(con votebarry post if conservative == 1 & learn == 0, col(black) msym(s) lpat(dash))
	(con votebarry post if conservative == 0 & learn == 1, col(black) msym(O) lpat(solid))
	(con votebarry post if conservative == 0 & learn == 0, col(black) msym(s) lpat(dash))
	,
		legend(
			order(1 "Learned" 2 "Did not")
			ring(0)
			pos(12)
			region(lwid(none))
		)
		ylab(0(.2)1, angle(horiz))
		xlab(0 "1" 1 "2")
		xtitle("Wave")
		ytitle("Proportion voting for winner")
		plotregion(style(none))
		text(.6 .5 "Liberals")
		text(.2 .5 "Conservatives")
		;

#delimit cr

gr export "figure 4.eps", replace
shell epstopdf "figure 4.eps"

tab totaln
